const allMoney=[100,50,20,5,1] ;

function changeMoney(n,allMoney){
    // 1. n 不断减少
    // 2. 出钱 n > allMoney[i] 
    const length = allMoney.length;
    const result = [] ; // 每项表示对应面值的张数
    for(let i =0;i<length;i++){
        if(n>=allMoney[i]){
            result[i]=parseInt(n/allMoney[i]);
            n = n-result[i] * allMoney[i];
        }
        else{
            result[i]=0;
        }
    }
    return result;
}

const result= changeMoney(126,allMoney);

console.log(result)